<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>登录</title>
		<script type="text/javascript" src="js/layui.all.js" ></script>
		<script type="text/javascript" src="js/layui.js" ></script>
		<script type="text/javascript" src="js/axios.min.js" ></script>
		<script type="text/javascript" src="js/jquery-1.9.1.min.js" ></script>
		<script type="text/javascript" src="js/vue.js" ></script>
		<link rel="stylesheet" href="css/layui.css" media="all"/>
		<link rel="stylesheet" href="css/yemian/login.css" />
	</head>
	<body>
		<div class="login-main" id="app">
			
				<span class="zi" style="font-size: 50px ; font-family:'_GB2312' ;font-weight: 500; font-style: italic; ">阿拉尔</span>
				<span class="zi" style="font-size: 28px ;">农业资源管理系统</span>
			
			<div class="login">
				<div class="biao">
				</div>
				<div class="xinxi-input">
					<div class="layui-icon layui-icon-username" id="yonghuming"></div>
					<div> <input type="text" class="input" placeholder="请输入用户名" v-model="userName"/></div>
					<div class="layui-icon layui-icon-password " id="mima"></div>
					<div> <input type="password" class="input" placeholder="请输入密码" v-model="password"/></div>
					<div class="layui-icon layui-icon-vercode " id="yanzheng"></div>
					<div> <input type="password" class="input1" placeholder="请输入验证码"v-model="checkCode" /></div>
					<div> <button class="button" @click="login">登录</button></div>
					<div><a href="" title="免费注册" class="zhuce">免费注册</a></div>
					<div><a href="main.html" title="返回主页" class="shouye">返回主页</a></div>
				</div>
			</div>
		</div>
		
		
	</body>
	<script type="text/javascript">
		var vue=new Vue({
			el:'#app',
			data:{
				userName:'',
				password:'',
				checkCode:''
			},
			created:function(){
					this.login();
			},
			methods:{
				login:function(){
					var self = this;
					var params = new URLSearchParams();
					params.append('userName',self.userName);
					params.append('password',self.password);
					/*params.append('checkCode',self.checkCode);*/
					axios.defaults.withCredentials=true;//让ajax携带cookie
					axios.post("http://localhost:8080/user/login",params).then(function(response){
						var object = response.data;
						if(object.status==200){
							/* userId = object.data.userId;
							window.sessionStorage.setItem("loginUser",userId);*/
							window.location.href="main.html";
						}else if(object.status==100){
							var name = object.data.name;
							window.sessionStorage.setItem("loginAdmin",name);
							window.location.href="index.html";
						}else if(object.status==404||object.status==405){
							alert(object.message);
						}
						
						
						
					}).catch(function(error){
							console.log(error);
					})	
				},
			}
	
		});
		
		
		
	</script>
</html>
